package com.hengpeng.itfin.persist.impl;

import java.util.Date;

import org.springframework.stereotype.Repository;

import com.hengpeng.common.persist.AbstractDao;
import com.hengpeng.common.persist.query.DynamicQuery;
import com.hengpeng.itfin.persist.AccountDao;
import com.hengpeng.itfinbase.persist.Account;

@Repository
public class AccountDaoImpl extends AbstractDao<Account> implements AccountDao {

    @Override
    public Account getAccountByUserId(Long userId) {
        DynamicQuery query = new DynamicQuery(Account.class);
        query.eq("userId", userId);
        return super.getSingleByDynamicQuery(query);
    }

    @Override
    public Account getAccountByUserIdAndSub(Long userId, String subaccountId) {
        DynamicQuery query = new DynamicQuery(Account.class);
        query.eq("userId", userId);
        query.eq("subAccountId", subaccountId);
        return super.getSingleByDynamicQuery(query);
    }

    @Override
    public int updateAccount(Account newAccount) {
        // update Account set
        // baseMoney=?1,freezeMoney=?2,totalfillMoney=?3,totaldrawMoney=?4,totalInvestMoney=?5,totalInvestNum=?6,
        // totalIncomeMoney=?7,baseMoneyCollect=?8,inComeMoneyCollect=?9,baseMoneyRepay=?10,interestMoneyRepay=?11,updateTime=?12,
        // version=?13 where id=?14 and version&lt;?15
        return super.exeNamedQuery(
                "account.updateAccount",
                new Object[] { newAccount.getBaseMoney(), newAccount.getFreezeMoney(), newAccount.getTotalfillMoney(),
                        newAccount.getTotaldrawMoney(), newAccount.getTotalInvestMoney(),
                        newAccount.getTotalInvestNum(), newAccount.getTotalIncomeMoney(),
                        newAccount.getBaseMoneyCollect(), newAccount.getInComeMoneyCollect(),
                        newAccount.getBaseMoneyRepay(), newAccount.getInterestMoneyRepay(), newAccount.getUpdateTime(),
                        newAccount.getVersion(), newAccount.getId(), newAccount.getVersion() });
    }

    @Override
    public int updateAccount(Long trnas_baseMoney, Long trnas_freezeMoney, Long trnas_totalfillMoney,
            Long trnas_totaldrawMoney, Long trnas_totalInvestMoney, Long trnas_totalInvestNum,
            Long trnas_totalIncomeMoney, Long trnas_baseMoneyCollect, Long trnas_inComeMoneyCollect,
            Long trnas_baseMoneyRepay, Long trnas_interestMoneyRepay, Date updateTime, Long id) {
        // update Account set
        // baseMoney=baseMoney+?1,freezeMoney=freezeMoney+?2,totalfillMoney=totalfillMoney+?3,
        //totaldrawMoney=totaldrawMoney+?4,totalInvestMoney=totalInvestMoney+?5,totalInvestNum=totalInvestNum+?6,
        //totalIncomeMoney=totalIncomeMoney+?7,baseMoneyCollect=baseMoneyCollect+?8,inComeMoneyCollect=inComeMoneyCollect+?9,
        //baseMoneyRepay=baseMoneyRepay+?10,interestMoneyRepay=interestMoneyRepay+?11,updateTime=?12
        // where id=?13
        return super.exeNamedQuery("account.updateAccountAdd", new Object[] { trnas_baseMoney, trnas_freezeMoney,
                trnas_totalfillMoney, trnas_totaldrawMoney, trnas_totalInvestMoney, trnas_totalInvestNum,
                trnas_totalIncomeMoney, trnas_baseMoneyCollect, trnas_inComeMoneyCollect, trnas_baseMoneyRepay,
                trnas_interestMoneyRepay, updateTime,id });
    }

}
